

<template>

  <div>
    <el-table :data="articles">
      <el-table-column prop="title" label="文章名称" width="140">
      </el-table-column>
      <el-table-column prop="body" label="文章内容" width="220">
      </el-table-column>

      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row._id)" type="text" size="small">编辑</el-button>
          <el-button @click="del(scope.row._id)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

<script>
export default {
  data() {
    return {
      articles: [],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$http.get("articles", this.form).then((res) => {
        this.articles = res.data;
      });
    },
    edit(id) {
      this.$emit("textId", id);
      let me = this;
      me.$emit("routerTo", "Edit");
    },
    del(id) {
      this.$http.delete(`articles/${id}`).then((res) => {
        this.$message({
          message: "文章删除成功",
          type: "success",
        });
        this.getData();
      });
    },
  },
};
</script>
  
<style>
</style>

